﻿// WndForIPC.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include "WndForIPC/IPCWndClient.h"
#include "WndForIPC/IPCWndServer.h"
#include "WndForIPC/IIPCWndCallBack.h"

class IPCCallback : public IIPCWndCallBack
{
public:
	virtual ~IPCCallback() {}
	virtual LRESULT OnProcessIPCMsg(UINT msg, WPARAM wparam, LPARAM lparam) 
	{
		char szBuf[100] = { 0 };
		sprintf_s(szBuf, "IPCCallback receive Msg:%d, wparam:%d, lparam:%d", msg, wparam, lparam);
		OutputDebugStringA(szBuf);
		return S_OK;
	}

	virtual LRESULT OnReceiveString(const std::wstring& strMsg) 
	{ 
		OutputDebugStringW(strMsg.c_str());
		return S_OK;
	}
	virtual LRESULT OnReceiveString(const std::string& strMsg) 
	{ 
		OutputDebugStringA(strMsg.c_str());
		return S_OK;
	}
};

int main()
{
	CIPCWndServer ipcServer;
	ipcServer.set_server_name(L"WndIpcServerName");
	IPCCallback callback;
	ipcServer.set_handler(&callback);
	ipcServer.start_listen();

	getchar();

	::SendMessage(ipcServer.get_hwnd(), 2352, 42, 36);
	::PostMessage(ipcServer.get_hwnd(), 2351, 4, 6);

	CIPCWndClient ipcClient;
	ipcClient.set_connect_host_name(L"WndIpcServerName");
	//ipcClient.set_host_server_hwnd(ipcServer.get_hwnd());  //或者用这个也可以  直接设置目标server的句柄
	ipcClient.post_message(234, 45, 66);
	ipcClient.send_message(688, 32, 16);
	ipcClient.send_msg_stringW(L"lzlong msg wstring");
	ipcClient.send_msg_stringA("lzlong msg string");

	getchar();

	ipcServer.stop_listen();
}
